package com.wei.czz.common.dto.annex;

import com.alibaba.fastjson2.JSON;
import com.wei.czz.common.tool.BaseEntity;
import com.wei.czz.common.vo.annex.AnnexConfigJsonVo;
import com.wei.czz.framework.annex.entity.AnnexConfigEntity;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-01-19 15:02:59
 * className: AnnexConfigDto
 * version: 1.0
 * description:
 */
@Getter
@Setter
@Accessors(chain = true)
public class AnnexConfigDto extends BaseEntity {

    /**
     * 主键
     */
    private String id;

    /**
     * 前置主键
     */
    private String preId;

    /**
     * 分组主键
     */
    private String groupId;

    /**
     * 配置json数据
     */
    private AnnexConfigJsonVo configJson;

    /**
     * 排序等级
     */
    private Integer sort;

    /**
     * 附件动态配置字段映射
     * @param annexField 附件动态配置字段对象
     * @return 映射结果
     */
    public static AnnexConfigDto map(AnnexConfigEntity annexField) {
        AnnexConfigDto annexConfigDto = new AnnexConfigDto();
        annexConfigDto.id = annexField.getId().toString();
        annexConfigDto.preId = annexField.getPreId().toString();
        annexConfigDto.groupId = annexField.getGroupId().toString();
        annexConfigDto.configJson = JSON.parseObject(annexField.getConfigJson(), AnnexConfigJsonVo.class);
        annexConfigDto.sort = annexField.getSort();
        return annexConfigDto;
    }
}
